package cn.wolfcode.handler;


import cn.wolfcode.damain.OrderInfo;
import cn.wolfcode.redis.SeckillRedisKey;
import com.alibaba.fastjson.JSON;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;
import top.javatool.canal.client.annotation.CanalTable;
import top.javatool.canal.client.handler.EntryHandler;

@Component
@CanalTable("t_order_info")
public class OrderInfoHandler implements EntryHandler<OrderInfo> {
    @Autowired
    private StringRedisTemplate redisTemplate;

    public void insert(OrderInfo t) {
        System.out.println(t);
        System.out.println("新增");
        redisTemplate.opsForHash().put(SeckillRedisKey.SECKILL_ORDER_HASH.getRealKey(""),
                t.getOrderNo(), JSON.toJSONString(t));
    }

    public void update(OrderInfo before, OrderInfo after) {
        System.out.println(before);
        System.out.println(after);
        System.out.println("修改");
        redisTemplate.opsForHash().put(SeckillRedisKey.SECKILL_ORDER_HASH.getRealKey(""),
                after.getOrderNo(), JSON.toJSONString(after));
    }

    public void delete(OrderInfo t) {
        System.out.println(t);
        System.out.println("删除");
    }
}
